Array.prototype.reduce=(callbackFn,initialValue)=>{
    if(Object.prototype.toString.call(callbackFn)!=='[object Function]'){
        throw new TypeError(callbackFn+'is not a function')
    }
    let arr=this;

    let startIndex=initialValue===undefined?0:1
    let accumulator=initialValue===undefined?arr[0]:arr[0]
    
    for(let i=startIndex;i<arr.length;i++){
        accumulator=callbackFn.call(undefined,accumulator,arr[i],arr)
    }
    return accumulator
}